package com.yc.web.controller.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
public class ResponseResult {
    private int code;
    private String msg;
    private Object data;

    // 添加Jackson反序列化支持的构造器
    @JsonCreator
    public ResponseResult(@JsonProperty("code") int code,
                          @JsonProperty("msg") String msg,
                          @JsonProperty("data") Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult ok() {
        return new ResponseResult(1, "操作成功", null);
    }

    public static ResponseResult ok(String message) {
        return new ResponseResult(1, message, null);
    }

    public static ResponseResult error() {
        return new ResponseResult(0, "操作失败", null);
    }

    public static ResponseResult error(String message) {
        return new ResponseResult(0, message, null);
    }

    public ResponseResult setData(Object data) {
        this.data = data;
        return this;
    }
}